home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / tcqbsnip.zip / BASICDOS.TXT next >
Text File  |  1997-05-04  |  6KB  |  139 lines

  1. 'A tutorial for Richard Backus' BASICDOS.BAS code.  Here is
  2. 'the code in the original form that he sent to me:
  3.  
  4. '===========>8 CLIP 8<============
  5.  
  6. '       BASICDOS.BAS
  7. ' written: Richard J Backus     27dec95
  8. ' purpose: to provide a BASIC BIOS/DOS call interface
  9. ' method: using the CALL interface, get registers, call the interrupt, and
  10. '       return the registers. Based on QuickBasic's CALL INTERRUPT routine.
  11. ' Warning: Calls requiring segment registers cannot be used.
  12.  
  13. ' QBasic syntax: CALL ABSOLUTE(intnum%, callregs, retregs, VARPTR(asmcode)))
  14. '   intnum%   a valid DOS interrupt number between 0 and 255, type INTEGER
  15. '   callregs  register values required by call, type REGS
  16. '   retregs   register values returned from call, type REGS
  17. TYPE REGS       'Typedef for DOS registers
  18.    ax  AS INTEGER
  19.    bx  AS INTEGER
  20.    cx  AS INTEGER
  21.    dx  AS INTEGER
  22.    bp  AS INTEGER
  23.    si  AS INTEGER
  24.    di  AS INTEGER
  25.    flg AS INTEGER
  26. END TYPE
  27. '       DOS call code
  28. DATA &H55, &H06, &H1E, &H8B, &HEC, &H9C, &H8B, &H7E, &H0E, &H8A
  29. DATA &H05, &H8B, &H7E, &H0C, &HB4, &H35, &HCD, &H21, &H8B, &H46
  30. DATA &HF8, &H05, &H20, &H00, &H0E, &H50, &H06, &H53, &H8B, &H05
  31. DATA &H8B, &H5D, &H02, &H8B, &H4D, &H04, &H8B, &H55, &H06, &H8B
  32. DATA &H6D, &H08, &H8B, &H75, &H0A, &H8B, &H7D, &H0C, &HFA, &HCB
  33. DATA &H1F, &H07, &H57, &H9C, &H8B, &HFC, &H36, &H8B, &H7D, &H0A
  34. DATA &H89, &H05, &H89, &H5D, &H02, &H89, &H4D, &H04, &H89, &H55
  35. DATA &H06, &H89, &H6D, &H08, &H89, &H75, &H0A, &H58, &H89, &H45
  36. DATA &H0E, &H58, &H89, &H45, &H0C, &H5D, &HCA, &H06, &H00
  37. '       Load DOS/BIOS interface routine
  38. DIM dos%(45)                    'get some memory space
  39. DEF SEG = VARSEG(dos%(0))
  40. FOR i% = 0 TO 88
  41.    READ d%
  42.    POKE VARPTR(dos%(0))+i%, d%  'copy code into memory
  43. NEXT i%
  44.  
  45. '       Message string
  46. DATA &H48, &H65, &H6C, &H6C, &H6F, &H20, &H57, &H6F, &H72, &H6C
  47. DATA &H64, &H0D, &H0A
  48. '       use DOS to output the message
  49. DIM dosregs AS REGS
  50. FOR i% = 0 TO 12
  51.    intnum% = &H21               'parameters for call
  52.    dosregs.ax% = &H200
  53.    READ dosregs.dx%
  54.    DEF SEG = VARSEG(dos%(0))    'set call seg
  55.    CALL ABSOLUTE(intnum%, dosregs, dosregs, VARPTR(dos%(0)))
  56. NEXT i%
  57. END
  58.  
  59. '=============>8 CLIP 8<================
  60.  
  61. 'TYPE REGS will set up the variable REGS to access all the registers
  62. 'you need to make a BIOS call.  This goes in hand with the DIM dosregs
  63. 'as REGS.  Dosregs will contain the information of the registers.  For
  64. 'example, if you want to send a value to the AX register, you can set
  65. 'dosregs.ax=value.  I'm not great at explaining how TYPE works, so best
  66. 'consult some books (or the help file) on that one. :)
  67.  
  68. 'Next he has his assembly routine that emulates CALL INTERRUPT.  This
  69. 'and the code under it that pokes the routine into memory is the heart
  70. 'of the whole thing.
  71.  
  72. 'Next, he creates the data for each character in the string "Hello
  73. 'World" and he uses a BIOS video call to place each character on the
  74. 'screen (much the same way my GPrint routine does in my GUI interface).
  75. '
  76. 'Note how he used CALL ABSOLUTE.  Lets compare it with QB45's CALL
  77. 'INTERRUPT syntax:
  78.  
  79. 'QB45:   CALL INTERRUPT (intnum%, dosregs, dosregs)
  80. 'QBASIC: CALL ABSOLUTE (intnum%, dosregs, dosregs, VARPTR(dos%(0)))
  81.  
  82. 'Notice all is basically the _same_, you just add the VARPTR at the
  83. 'end! And don't forget to change INTERRUPT to ABSOLUTE.  This makes it
  84. 'very easy to change a QB45 code to work with QBasic.
  85.  
  86. 'Now, I will try and explain how you can convert QB45 code that uses
  87. 'CALL INTERRUPT so that it will work in QBasic.  Of course, you'll need
  88. 'the code written by Richard Backus (which was posted in the previous
  89. 'message).  Also note this works only for the CALL INTERRUPT calls.  If
  90. 'you see CALL INTERRUPTX or CALL INT86, I'm not sure how it will work
  91. 'with those, as they take slightly different parameters.
  92.  
  93. 'First off, the QB45 program will have a '$INCLUDE statement in it.
  94. 'You must delete that statement.  Next, put the TYPE REGS in AFTER the
  95. 'DECLARE SUB and DECLARE FUNCTION statements (if any). You'll want to
  96. 'more than likely change REGS to RegType, as that is what the qb.bi was
  97. 'using.  This will replace it.
  98.  
  99. 'Now, put the DIM SHARED Inregs as RegType, Outregs as RegType with the
  100. 'DIM statements, if there isn't one there already.  Most often than
  101. 'not, it may not need changing.  Also add in DIM SHARED dos%(45) and
  102. 'DEF SEG = VARSEG(dos%(0)).  It should look something like this:
  103.  
  104. 'DIM and CONST, etc. here
  105. 'DIM SHARED Inregs as RegType, Outregs as RegType
  106. 'DIM SHARED dos%(45)
  107. 'DEF SEG = VARSEG(dos%(0))
  108.  
  109. 'Once you have the variables all set up, next slip the DOS Call Code
  110. 'data statements and the Load DOS/BIOS interface routine just before
  111. 'the main code of the program starts.  Most of the time, there's a CLS
  112. 'or SCREEN statement there.
  113.  
  114. 'Now just one more step.  Look through the code (may want to do a
  115. 'search for CALL INTERRUPT).  You will need to change each occurrence of
  116. 'INTERRUPT to ABSOLUTE.  And, you will need to add to the end of each
  117. 'CALL ABSOLUTE (which was a CALL INTERRUPT) the VARPTR statement.  For
  118. 'example, suppose the QB45 code read:
  119.  
  120. '  CALL INTERRUPT (intnum%, Inregs, Outregs)
  121.  
  122. 'You would change it to read:
  123.  
  124. '  CALL ABSOLUTE (intnum%, Inregs, Outregs, VARPTR(dos%(0)))
  125.  
  126. 'Be sure to get all the parenthesis right!  There's _3_ of them at the
  127. 'end of the ABSOLUTE statement (I say this because I'm bad at it and
  128. 'forget a lot! :)
  129.  
  130. 'Now you can save the new code to a new file name (for safe keeping)
  131. 'and run it.  It should work!
  132.  
  133. 'If you have any questions, let me know.  I can't promise I'll be able
  134. 'to have an answer every time but I'll try.  If you need to contact
  135. 'Richard, net mail me and I'll forward your question or whatever to
  136. 'him.  Just a short note that he does most of his programming in
  137. 'assembly. :)
  138.  
  139.